package com.ruoyi.web.controller.pets;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.pets.domain.PetFeedGuide;
import com.ruoyi.pets.service.IPetFeedGuideService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 宠物养护指南Controller
 * 
 * @author isc
 * @date 2024-03-12
 */
@RestController
@RequestMapping("/pets/guide")
public class PetFeedGuideController extends BaseController
{
    @Autowired
    private IPetFeedGuideService petFeedGuideService;

    /**
     * 查询宠物养护指南列表
     */
    @PreAuthorize("@ss.hasPermi('pets:guide:list')")
    @GetMapping("/list")
    public TableDataInfo list(PetFeedGuide petFeedGuide)
    {
        startPage();
        List<PetFeedGuide> list = petFeedGuideService.selectPetFeedGuideList(petFeedGuide);
        return getDataTable(list);
    }

    /**
     * 导出宠物养护指南列表
     */
    @PreAuthorize("@ss.hasPermi('pets:guide:export')")
    @Log(title = "宠物养护指南", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PetFeedGuide petFeedGuide)
    {
        List<PetFeedGuide> list = petFeedGuideService.selectPetFeedGuideList(petFeedGuide);
        ExcelUtil<PetFeedGuide> util = new ExcelUtil<PetFeedGuide>(PetFeedGuide.class);
        util.exportExcel(response, list, "宠物养护指南数据");
    }

    /**
     * 获取宠物养护指南详细信息
     */
    @PreAuthorize("@ss.hasPermi('pets:guide:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(petFeedGuideService.selectPetFeedGuideById(id));
    }

    /**
     * 新增宠物养护指南
     */
    @PreAuthorize("@ss.hasPermi('pets:guide:add')")
    @Log(title = "宠物养护指南", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PetFeedGuide petFeedGuide)
    {
        return toAjax(petFeedGuideService.insertPetFeedGuide(petFeedGuide));
    }

    /**
     * 修改宠物养护指南
     */
    @PreAuthorize("@ss.hasPermi('pets:guide:edit')")
    @Log(title = "宠物养护指南", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PetFeedGuide petFeedGuide)
    {
        return toAjax(petFeedGuideService.updatePetFeedGuide(petFeedGuide));
    }

    /**
     * 删除宠物养护指南
     */
    @PreAuthorize("@ss.hasPermi('pets:guide:remove')")
    @Log(title = "宠物养护指南", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(petFeedGuideService.deletePetFeedGuideByIds(ids));
    }
}
